package com.cskaoyan._03api;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/15 20:03
 **/

public class Temp {
    public static void main(String[] args) throws ParseException {
        // randomStr();
        // formatStr();

        Date date = new Date();
        System.out.println(date);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // Date---->String
        String s = sdf.format(date);
        System.out.println(s);

        // String ---> Date
        String dateStr = "2023-02-16 09:37:00";
        Date date1 = sdf.parse(dateStr);
        System.out.println(date1);

        long l = System.currentTimeMillis();
        System.out.println(l);


    }

    private static void formatStr() {
        // 000 001
        for (int i = 0; i < 100; i++) {
            // System.out.println(i);
            String s = String.format("%03d", i);
            System.out.println(s);
        }

        //double d = 3.1415926;
        //String s = String.format("%.2f", d);
        //System.out.println(s);
    }

    private static void randomStr() {
        String s = "0123456789";
        Random random = new Random();
        //String password = "";

        // char[]---->String
        char[] chars = new char[3];

        for (int i = 0; i < 3; i++) {
            //password += s.charAt(random.nextInt(s.length()));
            chars[i] = s.charAt(random.nextInt(s.length()));
        }
        //System.out.println(password);
        String str = new String(chars);
        System.out.println(str);
    }
}
